package com.brush.web.controller.pig;

import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.brush.pig.domain.req.pig.PigTransferAddReq;
import com.brush.pig.domain.req.pig.PigTransferEditReq;
import com.brush.pig.domain.req.pig.PigTransferQueryReq;
import com.brush.pig.domain.resp.pig.PigTransferResp;
import com.brush.pig.service.IotPigTransferService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping(value = "/admin/pig/transfer")
@Api(tags = "后台-猪猪转舍管理")
public class IotPigTransferController extends BaseController {

    @Autowired
    private IotPigTransferService pigTransferService;

    @PreAuthorize("@ss.hasPermi('system:post:list')")
    @ApiOperation(value = "分页查询")
    @GetMapping(value = "/list")
    public R<PageInfo<PigTransferResp>> list(PigTransferQueryReq req) {
        PageInfo<PigTransferResp> page = this.pigTransferService.paginationQuery(req);
        return R.ok(page);
    }

    @PreAuthorize("@ss.hasPermi('system:post:list')")
    @ApiOperation(value = "新增")
    @PostMapping
    public R add(@RequestBody @Valid PigTransferAddReq req) {
        boolean result = this.pigTransferService.add(req);
        return super.isSuccess(result);
    }

    @PreAuthorize("@ss.hasPermi('system:post:list')")
    @ApiOperation(value = "修改")
    @PutMapping
    public R edit(@RequestBody @Valid PigTransferEditReq req) {
        boolean result = this.pigTransferService.edit(req);
        return super.isSuccess(result);
    }


    @PreAuthorize("@ss.hasPermi('system:post:list')")
    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/{id}")
    public R<PigTransferResp> findById(@PathVariable(value = "id") Long id) {
        PigTransferResp pigTransferResp = this.pigTransferService.findById(id);
        return R.ok(pigTransferResp);
    }


}
